package com.yanqu.road.server.cmd.group.rank;

import com.yanqu.road.entity.enums.eBigRankType;
import com.yanqu.road.entity.enums.eRankType;
import com.yanqu.road.logic.cross.CrossGroupRankListModel;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.rank.CrossRankMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

@Cmd(code = CrossProtocol.C_CROSS_GROUP_RANK_TOP, desc = "分组跨服榜单榜首数据")
public class GetCrossGroupRankTopCmd extends CrossCommand {
    private int groupId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RankProto.CrossGroupRankTopReqMsg req = RankProto.CrossGroupRankTopReqMsg.parseFrom(packet.getBytes());
        groupId = req.getGroupId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        Map<Integer, Map<Integer, Map<Integer, CrossGroupRankListModel>>> modelMap = CrossRankMgr.getAllCrossGroupRankListModelMap();
        Map<Integer, Map<Integer, CrossGroupRankListModel>> rankMap = modelMap.get(groupId);
        if (rankMap == null) {
            return;
        }
        RankProto.RankTopOneRespMsg.Builder respMsg = RankProto.RankTopOneRespMsg.newBuilder();
        //赚速榜首
        RankProto.RankListMsg.Builder rankListMsg = rankMap.get(eBigRankType.Normal.getValue()).get(eRankType.EarnSpeed.getValue()).getRankListMsg();
        if (null != rankListMsg && rankListMsg.getRankListCount() > 0) {
            respMsg.setEarnSpeedRankTop(rankListMsg.getRankList(0));
        }
        //实力榜首
        rankListMsg = rankMap.get(eBigRankType.Normal.getValue()).get(eRankType.PatronsAbility.getValue()).getRankListMsg();
        if (null != rankListMsg && rankListMsg.getRankListCount() > 0) {
            respMsg.setAbilityRankTop(rankListMsg.getRankList(0));
        }
        //亲密度榜首
        rankListMsg = rankMap.get(eBigRankType.Normal.getValue()).get(eRankType.BeautyIntimacy.getValue()).getRankListMsg();
        if (null != rankListMsg && rankListMsg.getRankListCount() > 0) {
            respMsg.setIntimacyRankTop(rankListMsg.getRankList(0));
        }
        //商会榜首
        //商会榜首要发到商会跨服组装
//        RankProto.UnionRankListMsg.Builder unionListMsg = CrossRankMgr.getAllCrossGroupUnionRankListModelMap().get(groupId).getRankListMsg();
//        if (null != unionListMsg && unionListMsg.getRankListCount() > 0) {
//            respMsg.setUnionRankTop(unionListMsg.getRankList(0));
//        }
        respMsg.setGroupId(groupId);
        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_UNION_GROUP_RANK_TOP, respMsg);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
